package com.roger.myHome.service.impl;

import com.roger.myHome.mapper.CommonMapper;
import com.roger.myHome.service.ImMsgService;
import com.roger.myHome.service.Test2Service;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import javax.annotation.Resource;

@Service
public class ImMsgServiceImpl implements ImMsgService {

    @Resource
    private CommonMapper commonMapper;

    @Resource
    private Test2Service test2Service;

    @Override
    public void add() {
        try {
            commonMapper.insertSql("insert into tb_test1(id,name) values(1,'a')");

            boolean result = test2Service.add();

            if (!result) {
                throw new RuntimeException("test false");
            }

        } catch (Exception e) {
            System.out.println("============================");
            e.printStackTrace();
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

    }
}
